package com.ergwang.service.admin;

import com.ergwang.Model.admin.bo.ChangeOrderBO;
import com.ergwang.Model.admin.bo.OrdersByPageBO;
import com.ergwang.Model.admin.vo.*;
import com.ergwang.dao.OrderDao;
import com.ergwang.dao.OrderDaoImpl;

import java.util.List;

/**
 * @author：ergwang
 * @Date: 2020/5/31
 * @Time: 11:00
 */
public class OrderServiceImpl implements OrderService {

    OrderDao orderDao = new OrderDaoImpl();

    /**
     * 从servlet获取到请求体数据，分表查询获得响应数据
     * @param ordersByPageBO
     * @return
     */
    public PageOrdersVO ordersByPage(OrdersByPageBO ordersByPageBO) {
        // 查询总条数
        int total = orderDao.getTotalCounts(ordersByPageBO);
        // 查询当前分页的结果page1
        List<PageOrderInfoVO> orderInfoVOS = orderDao.ordersByPage(ordersByPageBO);
        PageOrdersVO pageOrdersVO = new PageOrdersVO();
        pageOrdersVO.setTotal(total);
        pageOrdersVO.setOrders(orderInfoVOS);
        return pageOrdersVO;
    }

    public void deleteOrder(String id) {
        orderDao.deleteOrder(id);
    }

    public OrderGetInfoVO OrderGetInfo(int id) {
        // 从order表中获取数据
        OrderGetInfoVO orderGetInfoVO = orderDao.OrderGetInfo(id);
        // 从spec表中获取对应的商品的spec
        List<OrderGetInfo_SpecVO> specList = orderDao.OrderGetInfo_Spec(orderGetInfoVO.getGoodsDetailId());

        // 汇总
        orderGetInfoVO.setSpec(specList.toArray(new OrderGetInfo_SpecVO[specList.size()]));
        return orderGetInfoVO;
    }

    /**
     * 修改订单，（暂时只实现了修改订单状态）
     * @param changeOrderBO
     */
    public void changeOrder(ChangeOrderBO changeOrderBO) {
        orderDao.changeOrder(changeOrderBO);
    }
}
